package com.zego.wawaji.ui.center.address.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.zego.wawaji.base.data.BaseData;

import org.json.JSONObject;

/**
 * 用户地址
 * Created by Su on 2017/12/1.
 */
public class Address extends BaseData implements Parcelable{
    private long id;    // 查表id
    private long uid;   // 用户id
    private String receiverName;  // 收获人姓名
    private String telephone; // 手机号
    private String province;  // 省
    private String city;      // 市
    private String district;  // 区
    private String street;    // 街道地址
    private int status;       // =1：默认

    @Override
    public void parseJson(String jsonStr) {
        JSONObject jsonObject = getJsonObject(jsonStr);

        this.setId(jsonObject.optLong("Id"));
        this.setUid(jsonObject.optLong("Uid"));
        this.setReceiverName(jsonObject.optString("ReceiverName"));
        this.setTelephone(jsonObject.optString("Telphone"));
        this.setProvince(jsonObject.optString("Province"));
        this.setCity(jsonObject.optString("City"));
        this.setStreet(jsonObject.optString("Street"));
        this.setStatus(jsonObject.optInt("Status"));
        this.setDistrict(jsonObject.optString("District"));
    }

    public String getDistrict() {
        return district;
    }

    public void setDistrict(String district) {
        this.district = district;
    }

    public boolean isDefault() {
        return status == 1;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getUid() {
        return uid;
    }

    public void setUid(long uid) {
        this.uid = uid;
    }

    public String getReceiverName() {
        return receiverName;
    }

    public void setReceiverName(String receiverName) {
        this.receiverName = receiverName;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }


    public Address() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.id);
        dest.writeLong(this.uid);
        dest.writeString(this.receiverName);
        dest.writeString(this.telephone);
        dest.writeString(this.province);
        dest.writeString(this.city);
        dest.writeString(this.district);
        dest.writeString(this.street);
        dest.writeInt(this.status);
    }

    protected Address(Parcel in) {
        this.id = in.readLong();
        this.uid = in.readLong();
        this.receiverName = in.readString();
        this.telephone = in.readString();
        this.province = in.readString();
        this.city = in.readString();
        this.district = in.readString();
        this.street = in.readString();
        this.status = in.readInt();
    }

    public static final Creator<Address> CREATOR = new Creator<Address>() {
        @Override
        public Address createFromParcel(Parcel source) {
            return new Address(source);
        }

        @Override
        public Address[] newArray(int size) {
            return new Address[size];
        }
    };
}
